package uplb.ics.cs190.e2d.math;


public class Rectangle {

	public int x;
	public int y;
	
	public int width;
	public int height;
	
	public Rectangle(int x, int y, int width, int height) {
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
	}
	
	public Rectangle() {
		this(0, 0, 0, 0);
	}
	
	public Rectangle(int width, int height) {
		this(0, 0, width, height);
	}
	
	public Rectangle(Point p, Dimension d) {
		this(p.x, p.y, d.width, d.height);
	}
	
	public Rectangle(Point p) {
		this(p.x, p.y, 0, 0);
	}
	
	public Rectangle(Dimension d) {
		this(0, 0, d.width, d.height);
	}
	
	public Point getLocation() {
		return new Point(this.x, this.y);
	}
	
	public void setLocation(Point p) {
		this.setLocation(p.x, p.y);
	}
	
	public void setLocation(int x, int y) {
		this.x = x;
		this.y = y;
	}
	
	public Dimension getSize() {
		return new Dimension(this.width, this.height);
	}
	
	public void setSize(Dimension d) {
		this.setSize(d.width, d.height);
	}
	
	public void setSize(int width, int height) {
		this.width = width;
		this.height = height;
	}
	
	public boolean contains(Point p) {
		return contains(p.x, p.y);
	}
	
	public boolean contains(int x, int y) {
		int w = this.width;
		int h = this.height;
		
		if((w | h) < 0) {
			return false;
		}
		
		int x2 = this.x;
		int y2 = this.y;
		if(x < x2 || y < y2) {
			return false;
		}
		
		w += x;
		h += y;
		
		return ((w < x2 || w > x) && (h < y2 || h > y));
	}
}